package com.projectx.action.login;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.text.TextPaint;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.material.textfield.TextInputLayout;
import com.projectx.R;
import com.projectx.action.findPassword.FindAccount;
import com.projectx.action.register.Register1;
import com.projectx.util.ActivityManage;

import org.litepal.LitePal;

public class LoginActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        LitePal.initialize(this);
        ActivityManage.addActivity("LoginActivity", this);
        setContentView(R.layout.acticity_login);


        final TextView textView = findViewById(R.id.LoginText);
        TextPaint textPaint = textView.getPaint();
        textPaint.setStyle(Paint.Style.FILL_AND_STROKE);
        textPaint.setStrokeWidth(2);

        final Button next = findViewById(R.id.LoginNext);
        final EditText accountInput = findViewById(R.id.AccountEditText);
        final Button forgetAccount = findViewById(R.id.ForgetAccount);
        final Button register = findViewById(R.id.RegisterAccount);
        final TextInputLayout textInputLayout = findViewById(R.id.AccountEditField);
        final Button learnMore = findViewById(R.id.learn_more);

        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(LoginActivity.this, "不能为空" ,Toast.LENGTH_SHORT).show();
                String account = accountInput.getText().toString();
                if (account.isEmpty()) {
                    textInputLayout.setError("账户名不能为空");
                } else {
                    textInputLayout.clearFocus();
                    textInputLayout.setError(null);
                    Intent intent = new Intent(LoginActivity.this, LoginActivity2.class);
                    intent.putExtra("accountName", account);
                    startActivity(intent);
                }
            }
        });

        forgetAccount.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LoginActivity.this, FindAccount.class);
                startActivity(intent);
            }
        });

        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LoginActivity.this, Register1.class);
                startActivity(intent);
                ActivityManage.removeAllActivityExcept("LoginActivity");
            }
        });

        learnMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder alert = new AlertDialog.Builder(LoginActivity.this);
                alert.setTitle("这本来是一个很长的故事");
                alert.setMessage("简短的来说：这是个事故\n是个事故\n事故");
                alert.setNeutralButton("唉，说多了都是泪", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        realDialog();
                    }
                }).setNegativeButton("后端祭天",null);
                alert.setCancelable(false).show();
            }
        });
    }

    private void realDialog (){
        AlertDialog.Builder alert = new AlertDialog.Builder(LoginActivity.this);
        alert.setTitle("这本来是一个很长的故事");
        alert.setMessage("简短的来说：这是个事故\n是个事故\n事故");
        alert.setNeutralButton("唉，说多了都是泪", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                realDialog();
            }
        }).setNegativeButton("后端祭天",null);
        alert.setCancelable(false).show();
    }

    @Override
    public void onBackPressed() {
        ActivityManage.removeActivity("LoginActivity");
        super.onBackPressed();
    }
}

